home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.06 Jun 91 / OQD Code / OQD_Test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-11  |  7.2 KB  |  273 lines  |  [TEXT/KAHL]

  1. /*******************************
  2. File: OQD_Test.c
  3. Function: Handle OQD_Test window
  4. *******************************/
  5. #include "OQD_Test.h"
  6. #include "OQDKolorize.h"
  7. #include "String.h"
  8.  
  9. #define      TRUE   1
  10. #define      FALSE  0
  11. #define      NIL    0
  12.  
  13. static void  Do_Button(ControlHandle theControl);
  14. static void  ClearRadioGroup(void);
  15. static  void  Do_A_Checkbox(ControlHandle theControl);
  16.  
  17.  
  18.     /* *********************************** */
  19. extern int checkmark;
  20. extern int colorSelection[4];
  21.  
  22. /* Control IDs */
  23. #define    ButtonID     28
  24. #define    CheckboxID     30
  25. #define    Radio1ID     29
  26. #define    Radio2ID     31
  27.  
  28. WindowPtr    MyWindow;
  29. static ControlHandle theButton;
  30. static ControlHandle theCheckbox;
  31. static ControlHandle theRadio[3];
  32.  
  33. void  Init_OQD_Test()
  34. /* initialize OQD_Test window */
  35. {
  36. MyWindow = NIL;
  37. }
  38.  
  39. void  Close_OQD_Test(whichWindow)
  40. /* dispose of OQD_Test window */
  41. WindowPtr  whichWindow;
  42. {
  43.      
  44. if ((MyWindow != NIL) && 
  45.     ((MyWindow == whichWindow) || (whichWindow == (WindowPtr)-1))) {
  46.     DisposeWindow(MyWindow); 
  47.     MyWindow = NIL; 
  48.     } 
  49. }
  50.  
  51. void DrawTheRect(theRect, theColor)
  52. Rect *theRect;
  53. int theColor;
  54. /* draws & frames rectangle with color */
  55. {
  56. FrameRect(theRect);
  57. InsetRect(theRect, 1, 1);
  58. ForeColor(theColor);
  59. PaintRect(theRect);
  60. ForeColor(blackColor);
  61. }
  62. void  UpDate_OQD_Test(whichWindow)
  63. WindowPtr  whichWindow;
  64. /* update window */
  65. {
  66. WindowPtr   SavePort;
  67. Str255   sTemp;
  68. Rect tempRect;
  69. int pallete[4];
  70.     
  71. if ((MyWindow != NIL)  &&  (MyWindow == whichWindow)) {
  72.     GetPort(&SavePort);
  73.     SetPort(MyWindow);
  74.     
  75.     /* Draw solid color rectangles */
  76.     SetRect(&tempRect, 20,40,80,100);
  77.         DrawTheRect(&tempRect, blackColor);
  78.     SetRect(&tempRect, 100,40,160,100);
  79.         DrawTheRect(&tempRect, whiteColor);
  80.     SetRect(&tempRect, 260,40,320,100);
  81.         DrawTheRect(&tempRect, greenColor);
  82.     SetRect(&tempRect, 180,40,240,100);
  83.         DrawTheRect(&tempRect, redColor);
  84.     SetRect(&tempRect, 260,140,320,200);
  85.         DrawTheRect(&tempRect, yellowColor);
  86.     SetRect(&tempRect, 180,140,240,200);
  87.         DrawTheRect(&tempRect, magentaColor);
  88.     SetRect(&tempRect, 100,140,160,200);
  89.         DrawTheRect(&tempRect, cyanColor);
  90.     SetRect(&tempRect, 20,140,80,200);
  91.         DrawTheRect(&tempRect, blueColor);
  92.     
  93.     /* Draw Mixed rectangle according to percentages */
  94.     SetRect(&tempRect, 360,100,420,160);
  95.     FrameRect(&tempRect);
  96.     InsetRect(&tempRect, 1, 1);
  97.     switch (checkmark) {
  98.         case 1: /* 75-25-0-0% of colorSelection */
  99.             pallete[0] = pallete[1] = pallete[2] = colorSelection[0];
  100.             pallete[3] = colorSelection[1];
  101.             break;
  102.         case 2: /* 50-50-0-0% of colorSelection */
  103.             pallete[0] = pallete[1] = colorSelection[0];
  104.             pallete[2] = pallete[3] = colorSelection[1];
  105.             break;
  106.         case 3: /* 50-25-25-0% of colorSelection */
  107.             pallete[0] = pallete[1] = colorSelection[0];
  108.             pallete[2] = colorSelection[1];
  109.             pallete[3] = colorSelection[2];
  110.             break;
  111.         case 4: /* 25-25-25-25% of colorSelection */
  112.             pallete[0] = colorSelection[0];
  113.             pallete[1] = colorSelection[1];
  114.             pallete[2] = colorSelection[2];
  115.             pallete[3] = colorSelection[3];
  116.             break;
  117.         }
  118.     PaintMixedRect(&tempRect, pallete);
  119.     
  120.     TextFont(systemFont);
  121.     /* Draw titles */
  122.     SetRect(&tempRect, 20,20,80,40);
  123.     strcpy((char *)&sTemp,"\pBlack");
  124.     TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
  125.     
  126.     SetRect(&tempRect, 100,20,160,40);
  127.     strcpy((char *)&sTemp,"\pWhite");
  128.     TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
  129.     
  130.     SetRect(&tempRect, 180,20,240,40);
  131.     strcpy((char *)&sTemp,"\pRed");
  132.     TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
  133.     
  134.     SetRect(&tempRect, 20,120,80,140);
  135.     strcpy((char *)&sTemp,"\pBlue");
  136.     TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
  137.     
  138.     SetRect(&tempRect, 260,20,320,40);
  139.     strcpy((char *)&sTemp,"\pGreen");
  140.     TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
  141.     
  142.     SetRect(&tempRect, 100,120,160,140);
  143.     strcpy((char *)&sTemp,"\pCyan");
  144.     TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
  145.     
  146.     SetRect(&tempRect, 180,120,240,140);
  147.     strcpy((char *)&sTemp,"\pMagenta");
  148.     TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
  149.     
  150.     SetRect(&tempRect, 260,120,320,140);
  151.     strcpy((char *)&sTemp,"\pYellow");
  152.     TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
  153.     
  154.     SetRect(&tempRect, 360,80,420,100);
  155.     strcpy((char *)&sTemp,"\pMixed");
  156.     TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
  157.     KolorizeMix(&tempRect, pallete);
  158.     TextFont(applFont);
  159.     
  160.     DrawControls(MyWindow);
  161.     
  162.     KolorizeCDEF(theButton, pushButProc, cyanColor, cyanColor);
  163.     
  164.     if (GetCtlValue(theRadio[0]))
  165.         KolorizeCDEF(theRadio[0], radioButProc, cyanColor, redColor);
  166.     else
  167.         KolorizeCDEF(theRadio[0], radioButProc, magentaColor, redColor);
  168.     
  169.     if (GetCtlValue(theRadio[1]))
  170.         KolorizeCDEF(theRadio[1], radioButProc, cyanColor, redColor);
  171.     else
  172.         KolorizeCDEF(theRadio[1], radioButProc, magentaColor, redColor);
  173.     
  174.     KolorizeCDEF(theCheckbox, checkBoxProc, greenColor, redColor);
  175.     SetPort(SavePort);
  176.     }
  177. }
  178.  
  179. void Open_OQD_Test(void)
  180. /* open OQD_Test window */
  181. {
  182. Rect tempRect;
  183.  
  184. if (MyWindow == NIL) {
  185.     MyWindow = GetNewWindow(1,NIL, (WindowPtr)-1);
  186.     tempRect = MyWindow->portRect;
  187.     tempRect.top = ((screenBits.bounds.bottom - screenBits.bounds.top) 
  188.                         - (tempRect.bottom - tempRect.top)) / 2 + 20;
  189.     tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left) 
  190.                         - (tempRect.right - tempRect.left)) / 2;
  191.     
  192.     MoveWindow(MyWindow, tempRect.left, tempRect.top, TRUE);
  193.     SetPort(MyWindow);
  194.     
  195.     /* Make buttons */
  196.     theButton = GetNewControl(ButtonID,MyWindow);
  197.     theCheckbox = GetNewControl(CheckboxID,MyWindow);
  198.     theRadio[0] = GetNewControl (Radio1ID, MyWindow);
  199.     theRadio[1] = GetNewControl (Radio2ID, MyWindow);
  200.     
  201.     ShowWindow(MyWindow);
  202.     SelectWindow(MyWindow);
  203.     UpDate_OQD_Test(MyWindow);
  204.     }
  205. else
  206.     SelectWindow(MyWindow);
  207. }
  208.  
  209. static  void  DoCheckbox(theControl)
  210. ControlHandle theControl;
  211. /* handle setting and kolorizing push and radio buttons */
  212. {
  213. short    theValue;
  214.  
  215. if (theControl == theCheckbox) { /* pushbutton */
  216.     theValue = GetCtlValue(theControl);
  217.     theValue = (theValue + 1) & 1;
  218.     SetCtlValue(theControl, theValue);
  219.     }
  220. else { /* radio buttons */
  221.     SetCtlValue(theRadio[0],0);
  222.     SetCtlValue(theRadio[1],0);
  223.     SetCtlValue(theControl, 1);
  224.     }
  225. }
  226.  
  227. void  Do_OQD_Test(myEvent)
  228. /* handle mouse downs in controls */
  229. EventRecord    *myEvent;
  230. {
  231. short    code;
  232. WindowPtr whichWindow;
  233. Point myPt;
  234. ControlHandle theControl;
  235.  
  236. if (MyWindow != NIL) { /* make sure our window */
  237.     code = FindWindow(myEvent->where, &whichWindow);
  238.     
  239.     /* see if mouse down */
  240.     if ((myEvent->what == mouseDown)  &&  (MyWindow == whichWindow)) {
  241.         myPt = myEvent->where;
  242.         GlobalToLocal(&myPt);
  243.         }
  244.     
  245.     /* see if control */
  246.     if ((MyWindow == whichWindow) &&  (code == inContent)) {
  247.         code = FindControl(myPt, whichWindow, &theControl);
  248.         if (code != 0) 
  249.             code = TrackControl(theControl,myPt, NIL);
  250.         if (code == inButton) /* only 1 button - Kolorize */
  251.             KolorizeCDEF(theButton, pushButProc, cyanColor, cyanColor);
  252.         if (code == inCheckBox) /* handle pushbutton and radios */
  253.             DoCheckbox(theControl);
  254.             KolorizeCDEF(theButton, pushButProc, cyanColor, cyanColor);
  255.         
  256.         /* Kolorize radios and checkbox */
  257.         if (GetCtlValue(theRadio[0]))
  258.             KolorizeCDEF(theRadio[0], radioButProc, cyanColor, redColor);
  259.         else
  260.             KolorizeCDEF(theRadio[0], radioButProc, magentaColor, redColor);
  261.         
  262.         if (GetCtlValue(theRadio[1]))
  263.             KolorizeCDEF(theRadio[1], radioButProc, cyanColor, redColor);
  264.         else
  265.             KolorizeCDEF(theRadio[1], radioButProc, magentaColor, redColor);
  266.         
  267.         KolorizeCDEF(theCheckbox, checkBoxProc, greenColor, redColor);
  268.         }
  269.     }
  270. }
  271.  
  272.  
  273.